<?php
namespace Application\pform\test;


use Application\model\ServerModel;
use Cola\Model;

class PlayerModel extends Model
{
    public function get($k, $default = '')
    {
        $data = $_GET[$k] ?? ($_POST[$k] ?? $default);

        return $data;
    }

    private function result($code=0, $msg='', $content=[])
    {
        return [
            'ret' => $code,
            'msg' => $msg,
            'content' => $content
        ];
    }
    public function notifyServer()
    {
        echo 'ok';
    }

    public function syncChat()
    {
        /*$account = $this->get('account');
        $account = substr($account, strpos($account, '-') + 1);
        $targetAccount = $this->get('target_account');
        $targetAccount = substr($targetAccount, strpos($targetAccount, '-') + 1);
        $data = $target = [];
        $channel = $this->get('channel');
        // 世界频道不上报
        $typeMap = [ 2=>2,3=>3,4=>1 ];
        if ($channel === 1 || !isset($typeMap[$channel])) return $this->result(0,'频道错误');

        $data['channel_id'] = 2;
        $data['xx_game_id'] = 3605;
        $data['server_id'] = $this->get('sid');
        $data['channel_user_id'] = $account;
        $data['role_id'] = $this->get('actor_id');
        $data['role_name'] = $this->get('actor_name');
        $data['role_level'] = $this->get('level');
        $data['user_ip'] = '127.0.0.1';
        $data['vip_level'] = $this->get('vip');
        $data['chat_type'] = $typeMap[$channel];
        $data['contents'] = $this->get('content');
        $data['chat_at'] = strtotime($this->get('chat_dt'));
        $data['timestamp'] = time();
        ksort($data);
        // 加密
        $data['sign'] = md5(http_build_query($data).GAME_SECRET);
        $data['money'] = $this->get('amount');
        $target['role_id'] = $this->get('target');
        $target['server_id'] = $this->get('target_sid');
        $target['channel_user_id'] = $targetAccount;
        $target['role_name'] = $this->get('target_actor_name');
        $target['role_level'] = $this->get('target_level');
        $target['vip_level'] = $this->get('target_vip');
        if ($data['chat_type'] === 1) $data['chat'] = $target;
        $res = curl(SYNC_CHAT_URL, $data);
        $this->logfile('sync chat:'.json_encode($data).' result:'.$res);*/
        return $this->result(1);
    }

}
